/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkUnicodeTextMapper.h,v $

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// .NAME vtkUnicodeTextMapper - 2D text annotation
// .SECTION Description
// vtkUnicodeTextMapper provides 2D text annotation support for VTK.  It is a
// vtkMapper that can be associated with a vtkActor and placed into a
// vtkRenderer.
//
// To use vtkUnicodeTextMapper, specify an input text string.

// .SECTION See Also
// vtkMapper vtkActor vtkLegendBoxActor vtkCaptionActor2D vtkVectorText vtkUnicodeTextProperty

#ifndef __vtkUnicodeTextMapper_h
#define __vtkUnicodeTextMapper_h

#include "vtkMapper.h"

class vtkActor;
class vtkUnicodeTextProperty;
class vtkViewport;

class VTK_EXPORT vtkUnicodeTextMapper : public vtkMapper
{
public:
  vtkTypeRevisionMacro(vtkUnicodeTextMapper,vtkMapper);
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Creates a new text mapper.
  static vtkUnicodeTextMapper *New();

  // Description:
  // Return the size[2]/width/height of the rectangle required to draw this
  // mapper (in pixels).
  virtual int GetWidth(vtkViewport*v);
  virtual int GetHeight(vtkViewport*v);
  
  // Description:
  // Set the input text string to the mapper.  The mapper recognizes "\n"
  // as a carriage return/linefeed (line separator).
  virtual void SetInput(const wchar_t *inputString);
//  vtkGetStringMacro(Input);
  wchar_t *GetInput()
  {
	  return Input;
  }
  // Description:
  // Set/Get the text property.
  virtual void SetTextProperty(vtkUnicodeTextProperty *p);
  vtkGetObjectMacro(TextProperty,vtkUnicodeTextProperty);
  
  // Description:
  // Shallow copy of an actor.
  void ShallowCopy(vtkUnicodeTextMapper *tm);
  
 
  // Description:
  // Set and return the font size required to make this mapper fit in a given 
  // target rectangle (width x height, in pixels). A static version of the method
  // is also available for convenience to other classes (e.g., widgets).  
  virtual int SetConstrainedFontSize(vtkViewport*, int targetWidth, int targetHeight);
  static int SetConstrainedFontSize(vtkUnicodeTextMapper*, vtkViewport*, int targetWidth, int targetHeight);

  // Description:
  // Set and return the font size required to make each element of an array
  // of mappers fit in a given rectangle (width x height, in pixels).  This
  // font size is the smallest size that was required to fit the largest
  // mapper in this constraint. 
  static int SetMultipleConstrainedFontSize(vtkViewport*, 
                                            int targetWidth, int targetHeight,
                                            vtkUnicodeTextMapper** mappers, 
                                            int nbOfMappers, 
                                            int* maxResultingSize);

  // Description:
  // Use these methods when setting font size relative to the renderer's size. These
  // methods are static so that external classes (e.g., widgets) can easily use them.
  static int SetRelativeFontSize(vtkUnicodeTextMapper*, vtkViewport*, int *winSize, 
                                 int *stringSize, float sizeFactor=0.0);
  static int SetMultipleRelativeFontSize(vtkViewport *viewport, 
                                         vtkUnicodeTextMapper **textMappers, 
                                         int nbOfMappers, int *winSize, 
                                         int *stringSize, float sizeFactor);

  // Description:
  // Get the available system font size matching a font size.
  virtual int GetSystemFontSize(int size) 
    { return size; }

  // Description:
  // Release any graphics resources that are being consumed by this actor.
  // The parameter window could be used to determine which graphic
  // resources to release.
  virtual void ReleaseGraphicsResources(vtkWindow *);
  
  // Description:
  // What is the size of the rectangle required to draw this
  // mapper ?
  virtual void GetSize(int size[2]);

  virtual void Render(vtkRenderer *ren, vtkActor *a);
  
  // Description:
  // Return bounding box (array of six doubles) of data expressed as
  // (xmin,xmax, ymin,ymax, zmin,zmax).
  virtual double *GetBounds();
  
  int GetLastLargestDescender(){return LastLargestDescender;};
protected:
  vtkUnicodeTextMapper();
  ~vtkUnicodeTextMapper();

  wchar_t* Input;
  vtkUnicodeTextProperty *TextProperty;

  int  LineSize;

  // These functions are used to parse, process, and render multiple lines 
  wchar_t *NextLine(const wchar_t *input, int lineNum);
  void RenderOverlayMultipleLines(vtkViewport *viewport, vtkActor *actor);
  virtual void RenderOverlay(vtkViewport*, vtkActor*);  

  vtkTimeStamp  SizeBuildTime;
  int LastSize[2];
  int LastLargestDescender;
private:
  vtkUnicodeTextMapper(const vtkUnicodeTextMapper&);  // Not implemented.
  void operator=(const vtkUnicodeTextMapper&);  // Not implemented.
};

#endif

